package com.junjie.blibli.api;

import com.junjie.blibli.Constant.AuthRoleConstant;
import com.junjie.blibli.Entity.UserMoment;
import com.junjie.blibli.Support.UserSupport;
import com.junjie.blibli.annotation.ApiLimitedRole;
import com.junjie.blibli.annotation.DataLimited;
import com.junjie.blibli.result.JsonResponse;
import com.junjie.blibli.service.UserMomentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserMomentsApi {
    @Autowired
    private UserMomentService userMomentService;

    @Autowired
    private UserSupport userSupport;

    //这里也参考了B站权限，如果用户是Lv0，是不能发动态的
    @ApiLimitedRole(limitedRoleCodeList = {AuthRoleConstant.ROLE_LV0})
    @DataLimited
    @PostMapping("/user-moments")
    public JsonResponse<String> addUserMoments(@RequestBody UserMoment userMoment) throws Exception{
        Long userId = userSupport.getCurrentUserId();
        userMoment.setUserId(userId);
        userMomentService.addUserMoments(userMoment);
        return JsonResponse.success();
    }

    //查询用户关注的人的一些动态信息
    @GetMapping("/user-subscribed-moments")
    public  JsonResponse<List<UserMoment>> getUserSubscribedMoments(){
        Long userId = userSupport.getCurrentUserId();
        List<UserMoment> list = userMomentService.getUserSubscribedMoments(userId);
        return new JsonResponse<>(list);
    }
}
